class Student(object):
  __slots__=('address','name','__idc') # 设置当前对象能动态新增的属性，新增其余属性报错
  type='human' # 设置类属性
  def __str__(self):
    return 'Student object (name： %s)' % self.name
  __repr__ = __str__ # __str__()返回用户看到的字符串，而__repr__()返回程序开发者看到的字符串，也就是说，__repr__()是为调试服务的。
  def __init__(self,name,idc):
    self.name = name
    self.__idc = idc # 下划线为私有属性，实例对象不能直接通过.idc获取，因为编译器将属性转译为_Student__idc
  def get_name(self):
    return self.name
  def get_idc(self):
    return self.__idc

s = Student('JyLie', '440')
print('Class is %s ,student is %s, and the type is %s' % (s,s.get_name(), Student.type))
print('--------------------')

class Animals(object):
  def eat(self):
    print('Animals is eating')
class Dargon(Animals):
  def eat(self):
    print('Dargon is eating')
  def fly(self):
    print('Dargon can fly')
dargon = Dargon()
print('%s:%s' % (dargon.eat(), dargon.fly()))
print('--------------------')

# 使用@property属性装饰器：限制属性读写操作
class Sea(object):
  def __init__(self,name,loc):
    self._name=name
    self.__loc = loc
  # 定义一个可读属性
  @property
  def name(self):
    return self._name
  # 定义一个可写属性
  @name.setter
  def name(self,name):
    self._name = name
  # 定义一个可读属性
  @property
  def loc(self):
    return self.__loc
sea = Sea('黄河','110,120')
print('Sea name is %s,and loc at %s' %(sea.name,sea.loc))
print('--------------------')

# 多重继承
class RunableMixin(object):
  def fly(self):
    print('can fily')
class Bird(Animals, RunableMixin):
  pass
bird = Bird()
print('the bird can %s and %s' % (bird.eat(),bird.fly()))
print('--------------------')

print('--------------------')
